package com.postsuperman.proxypool.service;

import cn.hutool.core.thread.ThreadUtil;
import com.postsuperman.proxypool.pojo.HttpProxy;

import java.util.List;
import java.util.concurrent.ExecutorService;

/**
 * @author ： Lwl postserupman
 * @Description TODO
 * @Date 2019/2/27 12:06
 * @Version 1.0
 */
public class BaseHttpProxyService implements HttpProxyService {

    protected Integer page = 1;

    protected Integer total = 1;

    protected Boolean chkPage = true;

    protected ExecutorService workerGroup = ThreadUtil.newExecutor(Runtime.getRuntime().availableProcessors() * 2);

    @Override
    public List<HttpProxy> get() {
        return null;
    }

    @Override
    public void setPage(Integer fristPage, Integer total) {
        if (fristPage != null && fristPage > -1) {
            this.page = fristPage;
        }
        if (total != null && total != 0) {
            chkPage = false;
            this.total = total;
        }
    }

    /**
     * 判断线程是否停止
     */
    protected void isTheardStop() {
        workerGroup.shutdown();
        try {
            while (true) {
                if (workerGroup.isTerminated()) {
                    System.out.println("当前线程任务执行完毕");
                    break;
                }

                Thread.sleep(200);
            }
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}
